<template>
  <el-table :data="tableData" border style="width: 100%" size="mini" stripe>
    <el-table-column prop="code" label="项目值" width="250"></el-table-column>
    <el-table-column prop="value" label="项目编码" width="150"></el-table-column>
    <el-table-column prop="remark" label="备注"  ></el-table-column>
    <el-table-column label="操作" width="200">
      <template slot-scope="scope">
        <el-button type="text" size="small" @click="addSP('edit',scope.row)">编辑</el-button>
        <el-button type="text" size="small" @click="del(scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
import { request } from "../../assets/request.js";
export default {
  data() {
    return {
      tableData: [],
      actData:''
    };
  },
  created(){
    let that=this
    this.$root.$on("handleNodeClick", data=>{
      if(data!='no'){
         this.actData=data
      }
      this.selectList(that.actData.id)
    });
    this.$root.$on("saveSP", data=>{
      this.selectList(that.actData.id)
    });
  },
  methods: {
    addSP(type,row){ 
        this.$root.$emit("addSP",type,row);
    },
    del(row) {
      let that=this 
      request.delAlert({
          name:'删除该参数',
          that,
          fn(obj){
              let url='constant/'+row.id+'?greenToken='+request.greenToken
              request.ajaxDel({
                url,
                that,
                fn(res){
                  that.$message(obj)
                  that.selectList(that.actData.id)
                  that.$store.state.positionList=''
                }
              })
          }
      })
    },
    selectList(obj) {
        let url = "constant/second/"+obj;
        let that=this   //解决this指向问题
        request.ajaxGet({
            url,
            that,
            fn(res){
                that.tableData=res
            }
        })
    }
  }
};
</script>
<style lang="less" scoped>
</style>
